package viewPackage.menus;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;

import mainPackage.GFrame;
import modelPackage.Player;

@SuppressWarnings("serial")
public class PausePanel extends JPanel {

	private GFrame gameFrame;
	
	public PausePanel(GFrame frame, final Player p) {
		super();
		gameFrame = frame;
		
		this.setBackground(new Color(0,0,0,128));
		
		TransMenuLabel title = new TransMenuLabel("Game is Paused", 48);
		final TransMenuLabel resume = new TransMenuLabel("Resume", 20);
		final TransMenuLabel mainMenu = new TransMenuLabel("Exit to Main Menu", 20);
		final TransMenuLabel exitGame = new TransMenuLabel("Exit Program", 20);
		
		
		/*
		JButton resume = new JButton("Resume");
		resume.setBorderPainted(false);
		resume.setBackground(new Color(0,0,0,128));
		resume.setForeground(Color.YELLOW);
		resume.setFont(new Font("SansSerif", Font.BOLD, 20));
		resume.setContentAreaFilled(false);
		resume.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				p.setPaused(false);
				JPanel game = null;
				CardLayout cl = (CardLayout) gameFrame.getContentPane().getLayout();
				if (p.getReturnTo() == 2) {
					cl.show(gameFrame.getContentPane(), "Game");
					game = (JPanel) (gameFrame.getContentPane().getComponent(0));
					game.grabFocus();
				}
				else if (p.getReturnTo() == 3){
					cl.show(gameFrame.getContentPane(), "3D");
					game = (JPanel) (gameFrame.getContentPane().getComponent(1));
					game.grabFocus();
				}	
			}
		});
		*/
		
		
		resume.addMouseListener(new JLabelMouse(resume) {
			@Override
			public void mouseEntered(MouseEvent arg0) {
				super.mouseEntered(arg0);
				resume.setBackground(new Color(0,0,0,128));
			}
			@Override
			public void mouseExited(MouseEvent arg0) {
				super.mouseExited(arg0);
				resume.setBackground(new Color(0,0,0,128));
			}
			@Override
			public void mouseClicked(MouseEvent arg0) {
				p.setPaused(false);
				JPanel game = null;
				CardLayout cl = (CardLayout) gameFrame.getContentPane().getLayout();
				if (p.getReturnTo() == 2) {
					cl.show(gameFrame.getContentPane(), "Game");
					game = (JPanel) (gameFrame.getContentPane().getComponent(0));
					game.grabFocus();
				}
				else if (p.getReturnTo() == 3){
					cl.show(gameFrame.getContentPane(), "3D");
					game = (JPanel) (gameFrame.getContentPane().getComponent(1));
					game.grabFocus();
				}				
			}});
		
		
		mainMenu.addMouseListener(new JLabelMouse(mainMenu) {
			@Override
			public void mouseEntered(MouseEvent arg0) {
				super.mouseEntered(arg0);
				mainMenu.setBackground(new Color(0,0,0,128));
			}
			@Override
			public void mouseExited(MouseEvent arg0) {
				super.mouseExited(arg0);
				mainMenu.setBackground(new Color(0,0,0,128));
			}
			@Override
			public void mouseClicked(MouseEvent arg0) {
				gameFrame.getContentPane().removeAll();
				gameFrame.getContentPane().setLayout(new BorderLayout());
				gameFrame.getContentPane().add(new MainMenuPanel(gameFrame), BorderLayout.CENTER);
				gameFrame.validate();
				gameFrame.repaint();
			}});
		
		exitGame.addMouseListener(new JLabelMouse(exitGame) {
			@Override
			public void mouseEntered(MouseEvent arg0) {
				super.mouseEntered(arg0);
				exitGame.setBackground(new Color(0,0,0,128));
			}
			@Override
			public void mouseExited(MouseEvent arg0) {
				super.mouseExited(arg0);
				exitGame.setBackground(new Color(0,0,0,128));
			}
			@Override
			public void mouseClicked(MouseEvent arg0) {
				System.exit(0);
			}});
		
		this.setLayout(new GridBagLayout());
		
		Constraints Ctitle = new Constraints(0,0,1,1,true);
		Constraints Cresume = new Constraints(0,1,1,1,false);
		Constraints CmainMenu = new Constraints(0,2,1,1,false);
		Constraints CexitGame = new Constraints(0,3,1,1,false);
		
		this.add(title, Ctitle);
		this.add(resume, Cresume);
		this.add(mainMenu, CmainMenu);
		this.add(exitGame, CexitGame);
		
		
	}	
	
}
